package com.example.boot.controller;

import com.example.boot.entity.User;
import com.example.boot.service.UserService;
import com.lemon.core.log.annotation.OperateLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author pan
 * @since 2022-03-22
 */
@Api(tags = "用户管理")
@RequiredArgsConstructor
@RestController
@RequestMapping("/user")
public class UserController {

    private final UserService userService;

    @ApiOperation("查询用户信息")
    @GetMapping
    public User getUser(@RequestParam(value = "name", defaultValue = "zhangsan") String name) {
        return userService.getUserByName(name);
    }

    @ApiOperation("记录日志")
    @OperateLog(module = "模块", name = "记录日志")
    @GetMapping("/log")
    public String logUser(String name) {
        return "ok " + name;
    }

    @ApiOperation("查询用户列表")
    @GetMapping("/list")
    public List<User> listUser() {
        return userService.list();
    }
}
